<template>
	<view class="main">
		<tou_hand1 handtitle='添加用户'></tou_hand1>
		<view class="show">
			<view class="sone">
				<view class="soneleft">姓名<span style="color: #F03D3D;">*</span>：</view>
				<input placeholder="请输入姓名" v-model="realName"/>
			</view>
			<view class="sone">
				<view class="soneleft">电卡号<span style="color: #F03D3D;">*</span>：</view>
				<input placeholder="请输入电卡号" v-model="cardId" type="number"/>
			</view>
			<view class="sone">
				<view class="soneleft">手机号：</view>
				<input placeholder="请输入手机号(非必填)" v-model="phone" type="number"/>
			</view>
			
			<view class="stwo" @click="joinbtn">
				立即添加
			</view>
		</view>
	</view>
</template>

<script>
	import tou_hand1 from '../../components/tou_hand1/tou_hand1.vue'
	
	export default {
		components: {tou_hand1},
		mounted() {
			
		},

		data() {
			return {
				realName:'',//姓名
				phone:'',//手机
				cardId:'',//电卡号
				projectId:'',//小区id
			}
		},
		onLoad(options) {
			this.projectId=options.projectId
		},
		methods: {
			joinbtn(){
				if(!this.realName){
					uni.showToast({
						title: '请输入姓名',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				// if(!this.phone){
				// 	this.$toast.fail('请输入手机号')
				// 	return
				// }
				if (!(/^1[3-9]\d{9}$/.test(this.phone))&&this.phone) {
					uni.showToast({
						title: '请输入正确的手机号格式',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				if(!this.cardId){
					uni.showToast({
						title: '请输入电卡号',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				if(this.cardId.length!=10){
					uni.showToast({
						title: '请输入10位电卡号',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				let data={
					realName:this.realName,
					phone:this.phone,
					cardId:this.cardId,
					appid:uni.getStorageSync('user').appid
				}
				this.$base.request1('manager/user'+'/'+this.projectId, 'POST',data)
					.then(res => {
						if(res.data.code==200){
							uni.showToast({
								title: '添加成功',
								duration: 2000,
							});
							uni.navigateBack()
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					})
					.catch(err => {
						
					})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		overflow-x: hidden;
		
		.show{
			width: 100%;
			box-sizing: border-box;
			margin-top: 61upx;
			.sone{
				width: 683upx;
				margin: 0 auto;
				box-sizing: border-box;
				padding-bottom: 30upx;
				border-bottom:1upx solid #e5e5e5;
				display: flex;
				align-items: center;
				margin-bottom: 28upx;
				.soneleft{
					font-size: 24upx;
					font-family: PingFang SC Medium, PingFang SC Medium-Medium;
					font-weight: 500;
					color: #333333;
					width: 34%;
				}
				input{
					font-size: 28upx;
					font-family: PingFang SC Medium, PingFang SC Medium-Medium;
					font-weight: 500;
					color: #999999;
				}
			}
			.stwo{
				width: 686upx;
				height: 88upx;
				border-radius: 8upx;
				font-size: 32upx;
				font-family: PingFang SC Bold, PingFang SC Bold-Bold;
				font-weight: 700;
				text-align: center;
				color: #ffffff;
				line-height: 88upx;
				margin: 0 auto;
				background-color: #4B98ED;
				margin-top: 350upx;
			}
		}
		
	}
</style>
